package cn.itcast.config;


import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.client.RestTemplate;

//@Configuration //用了springCache框架之后，key的序列化不会乱码，所以这个不用配置了
//Springdata_redis 默认帮我们创建的RedisTemplate对象是使用jdk的序列号器帮我们将键与值存储到redis中，而jdk的序列号器默认是使用二进制的方式存储，因此我们
//需要看的懂得花，需要去修改redistemplate的序列号器才行
public class RedisConfig {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
       redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
        return redisTemplate;

    }
}
